package cn.edu.bjut.homework.chapter4;

import java.util.Objects;

public class Classification {
    protected char section;
    protected int class_num;
    protected char subclass;
    protected int main_group;
    protected int sub_group;

    public char getSection() {
        return section;
    }

    public int getClass_num() {
        return class_num;
    }

    public char getSubclass() {
        return subclass;
    }

    public int getMain_group() {
        return main_group;
    }

    public int getSub_group() {
        return sub_group;
    }

    public void setSection(char section) {
        this.section = section;
    }

    public void setClass_num(int class_num) {
        this.class_num = class_num;
    }

    public void setSubclass(char subclass) {
        this.subclass = subclass;
    }

    public void setMain_group(int main_group) {
        this.main_group = main_group;
    }

    public void setSub_group(int sub_group) {
        this.sub_group = sub_group;
    }

    public Classification(char section, int class_num, char subclass, int main_group, int sub_group) {
        this.section = section;
        this.class_num = class_num;
        this.subclass = subclass;
        this.main_group = main_group;
        this.sub_group = sub_group;
    }

    public Classification(String s) {
        this.section = s.charAt(0);
        this.class_num = Integer.parseInt(s.substring(1, 3));
        this.subclass = s.charAt(3);
        int pos = s.indexOf('/');
        this.main_group = Integer.parseInt(s.substring(4, pos).trim());
        this.sub_group = Integer.parseInt(s.substring(pos + 1).trim());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Classification that = (Classification) o;
        return section == that.section && class_num == that.class_num && subclass == that.subclass && main_group == that.main_group && sub_group == that.sub_group;
    }

    @Override
    public int hashCode() {
        return Objects.hash(section, class_num, subclass, main_group, sub_group);
    }
}
